/**
 * Created by hms on 2020-08-21.
 * 登录模块
 */
import { setToken,delToken,setCookie,delCookie } from '@/utils/cookie.js'

export const Login = {
    state:{
        username:'',
        session_id:''
    },
    mutations:{
        setLogin(state,data){
            setToken(data.info.session_id);
            setCookie('retire_username',data.info.username);
            state.username = data.info.username;
            state.session_id = data.info.session_id;
        },
        setLogout(state,data){
            state.username = data.username;
            state.session_id = data.session_id;
        }
    },
    actions:{
        loadLogout(context,data){
            let log_info={
               username:'',
               session_id:''
            }
            context.commit('setLogout',log_info);
            delToken();
            delCookie('retire_user_name');
        }
    },
    getters:{
        getLoginUsername: state =>{
            return state.username
        },
        getSessionId: state =>{
            return state.session_id
        }
    }
}
